//手动实现call 遵循谁调用函数this指向谁的原则
Function.prototype.mycall = function (obj, ...args) {
  let val
  obj.fn = this
  val = obj.fn(...args)
  delete fn
  return val
}
let test = {
  name: "test"
}
let o = {
  name: 'o',
  speak: function (x) {
    console.log(this.name + x)
  }
}
//手动实现apply
Function.prototype.myApply = function (obj, arr) {
  let args = [];
  for (let i = 0; i < arr.length; i++) {
    args.push(arr[i]);
  }
  // 利用mycall实现
  let val
  obj.fn = this
  val = obj.fn(...args)
  delete fn
  return val
}
//手动实现bind 即返回一个函数就行
Function.prototype.mybind = function (obj, ...args) {
  let _this = this
  return function () {
    let val
    obj.fn = _this
    val = obj.fn(...args)
    delete fn
    return val
  }
}
let arr = [1, 2, 3, 4]
console.log(Math.max.myApply(this, arr))